www.gusucode.com > vc++ 远程控制示例源程序-源码程序 > vc++ 远程控制示例源程序-源码程序\code\PeerYouC\WriteScreen.cpp
//Download by http://www.NewXing.com // WriteScreen.cpp : implementation file // #include "stdafx.h" #include "peeryouc.h" #include "WriteScreen.h" #include "EditWriteScreen.h" #include "command.h" #include "peersocket.h" #include "peersplitterwnd.h" #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif ///////////////////////////////////////////////////////////////////////////// // CWriteScreen IMPLEMENT_DYNCREATE(CWriteScreen, CFormView) CWriteScreen::CWriteScreen() : CFormView(CWriteScreen::IDD) { //{{AFX_DATA_INIT(CWriteScreen) //}}AFX_DATA_INIT CFont font; font.CreateFont(-13,0,0,0,400,0,0,0,134,3,2,1,2,"宋体"); font.GetLogFont(&logFont); font.DeleteObject(); clrColor=RGB(0,0,0); } CWriteScreen::~CWriteScreen() { } void CWriteScreen::DoDataExchange(CDataExchange* pDX) { CFormView::DoDataExchange(pDX); //{{AFX_DATA_MAP(CWriteScreen) //}}AFX_DATA_MAP } BEGIN_MESSAGE_MAP(CWriteScreen, CFormView) //{{AFX_MSG_MAP(CWriteScreen) ON_WM_SIZE() ON_BN_CLICKED(IDC_BUTTON2, OnButton2) ON_BN_CLICKED(IDC_BUTTON3, OnButton3) //}}AFX_MSG_MAP END_MESSAGE_MAP() ///////////////////////////////////////////////////////////////////////////// // CWriteScreen diagnostics #ifdef _DEBUG void CWriteScreen::AssertValid() const { CFormView::AssertValid(); } void CWriteScreen::Dump(CDumpContext& dc) const { CFormView::Dump(dc); } #endif //_DEBUG ///////////////////////////////////////////////////////////////////////////// // CWriteScreen message handlers void CWriteScreen::OnSize(UINT nType, int cx, int cy) { CFormView::OnSize(nType, cx, cy); // TODO: Add your message handler code here } void CWriteScreen::OnButton2() { // TODO: Add your control notification handler code here CFontDialog bb(&logFont); if (bb.DoModal()==IDOK) { bb.GetCurrentFont(&logFont); clrColor=bb.GetColor(); } } void CWriteScreen::OnButton3() { // TODO: Add your control notification handler code here SOCKET s; WSAEVENT hEvent; COMMAND com; DWORD retLen; hEvent=WSACreateEvent(); if(hEvent==WSA_INVALID_EVENT) { return; } if(!PeerCreateSocket(&s,PEER_STREAM)) { WSACloseEvent(hEvent); return; } if(!PeerConnectSocket(s,ADDRESS,7788)) { WSACloseEvent(hEvent); closesocket(s); return; } com.CommandID=PEER_FONTTEXT; if(!PeerSendDataS(s,(char*)&com,sizeof(com),&retLen,hEvent)) { WSACloseEvent(hEvent); closesocket(s); return; } CPeerSplitterWnd* splitter=(CPeerSplitterWnd*)GetParent(); CEditWriteScreen* sctrl=(CEditWriteScreen*)splitter->GetPane(1,0); FONTTEXT ftext; ftext.color=clrColor; memcpy((char*)&ftext.logfont,(char*)&logFont,sizeof(LOGFONT)); // CString text; // sctrl->GetEditCtrl().GetWindowText(text); memcpy((char*)&ftext.text,sctrl->LockBuffer(),sctrl->GetBufferLength()); ftext.textcount=sctrl->GetBufferLength(); sctrl->UnlockBuffer(); if(!PeerSendDataS(s,(char*)&ftext,sizeof(ftext),&retLen,hEvent)) { WSACloseEvent(hEvent); closesocket(s); return; } WSACloseEvent(hEvent); closesocket(s); }